package com.ruoyi.app.controller;

import com.ruoyi.app.domain.Doctor;
import com.ruoyi.app.domain.DoctorSchedule;
import com.ruoyi.app.service.DoctorScheduleService;
import com.ruoyi.app.service.DoctorService;
import com.ruoyi.app.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("schedule")
@RestController
public class DoctorScheduleController {
    @Autowired
    private DoctorScheduleService doctorScheduleService;
    @Autowired
    private DoctorService doctorService;

    @RequestMapping("list")
    public Result getDoctorSchedule(@RequestParam Integer departmentId, @RequestParam String scheduleDate){
        List<DoctorSchedule> doctorSchedule = doctorScheduleService.getDoctorSchedule(departmentId, scheduleDate);
        for (DoctorSchedule schedule : doctorSchedule) {
            Doctor doctor = doctorService.selectDoctorById(schedule.getDoctorId());
            schedule.setDoctorName(doctor.getName());
        }
        return Result.ok(doctorSchedule);
    }
}
